<style>
.top3{font-size:40px;font-weight: bold;color:#3891CA;}
</style>
<table id="ranklist" class="n-table n-size-full">
	<tbody>
		<tr>
			
			<th>排名</th>
			<th>公众号</th>
			<th>发布</th>
			<th>总阅读数</th>
			<th>头条</th>
			<th>平均</th>
			<th>最高</th>
			<th>总点赞数</th>
			<th>中指数</th>
			<?php if ($data['needCart'] == 'Y'):?>
			<th>收藏</th>
			<?php endif;?>
		</tr>
	<?php $count = 1;?>
	<?php foreach ($data['rank_mplist'] as $mp):?>
		<tr>
			<td style="text-align: center;vertical-align: middle;">
				<?php
				if($count<=3){
					?>
					
					<span class="top3"><?=$count?></span>
					<?php
				}else{
					?>
						<?=$count?>
					<?php
				}
				?>
			</td>
			<td>
				<a href="<?=n_url('weixin', 'detail', ['wxid'=>$mp['wxid']])?>" target="_blank">
				<?php
				if($count<4){
				?>
				<img style="display:inline;margin-right:10px;width:40px;" src="/static/weixin_face/<?=$mp['wxid']?>.jpg" /><br />
				<?php
				}
				?>
					<?=$mp['wxname']?>
					<br />
					<?=$mp['wxid']?></a></td>
			<td><?=$mp['pub_times']?>/<?=$mp['pub_num']?></td>
			<td><?=$mp['all_read_num']?></td>
			<td><?=$mp['head_read_num']?></td>
			<td><?=$mp['average_read_num']?></td>
			<td><?=$mp['max_read_num']?></td>
			<td><?=$mp['all_like_num']?></td>
			<td><?=$mp['weixin_index']?></td>
			<?php if ($data['needCart'] == 'Y'):?>
			<td>
				<?php if (in_array($mp['wxid'], $data['cart'])):?>
					<a class="mpadd" href="javascript:void(0);" wxid="<?=$mp['wxid']?>">
						<img width="30" src="<?=n_img('skin','delete.png')?>" />
					</a>
				<?php else:?>
					<a class="mpadd add" href="javascript:void(0);" wxid="<?=$mp['wxid']?>">
						<img width="30" src="<?=n_img('skin','add.png')?>" />
						</a>
				<?php endif;?>
			</td>
			<?php endif;?>
		</tr>
	<?php $count++; endforeach;?>
	</tbody>
</table>
<?php
if($count==21){
?>
<div class="more-page">
	<a href="javascript:void(0);" onclick="more()">更多</a>
</div>
<?php
}
?>
<script>
var rurl = "<?=n_url('cart', 'delete')?>";
var aurl = "<?=n_url('cart', 'add')?>";
var rimg = "<?=n_img('skin', 'delete.png')?>";
var aimg = "<?=n_img('skin', 'add.png')?>";

function addToggle(obj){
	var wxid = $(obj).attr('wxid');
	if($(obj).hasClass('add')){
		$.getJSON(rurl,{wxid:wxid},function(){
			$(obj).find("img").attr('src',rimg);
			$(obj).removeClass('add');
		});
	}else{
		$.getJSON(rurl,{wxid:wxid},function(){
			$(obj).find("img").attr('src',aimg);
			$(obj).addClass('add');
		});
		
	}
}


$(document).ready(function(){
	$(".mpadd").click(function(){
		addToggle(this)
	});
});


var page = 1;
var cid = "<?=urlencode($data['category']['id'])?>";
var day = "<?=date('Y-m-d', $data['date'])?>";
var num = "<?=$count?>";
function more(){

	if(page==-1){
		$(".more-page").hide();
		return ;
	}
	page++;
	<?php 
		if ($data['type'] == 'day')
			$more = 'rankDailyMore';
		if ($data['type'] == 'week')
			$more = 'rankWeeklyMore';
	?>
	$.getJSON("<?=n_url('mprank', $more)?>",{cid:cid,date:day,page:page},function(data){
		if(!data.state){
			$(".more-page").hide();
			page=-1;
		}else{
			if(data.data.length!=20){
				$(".more-page").hide();
				page=-1;				
			}
			for(i in data.data){
				var tr = $("<tr>");
				var a = $("<a>")
								.attr("href","/weixin/detail.html?wxid="+data.data[i]['wxid'])
								.attr("target","_blank")
								.html(data.data[i]['wxname']+'<br />'+data.data[i]['wxid']);

				var add = $("<a>")
								.attr("href","javascript:void(0);")
								.attr("target","_blank")
								.attr("wxid",data.data[i]['wxid'])
								.html("<img width='30' src='"+aimg+"' />")
								.click(function(){addToggle(this)});

				$("<td>").text(num++).appendTo(tr);
				$("<td>").append(a).appendTo(tr);
				$("<td>").text(data.data[i]['pub_times']+'/'+data.data[i]['pub_num']).appendTo(tr);
				$("<td>").text(data.data[i]['all_read_num']).appendTo(tr);
				$("<td>").text(data.data[i]['head_read_num']).appendTo(tr);
				$("<td>").text(data.data[i]['average_read_num']).appendTo(tr);
				$("<td>").text(data.data[i]['max_read_num']).appendTo(tr);
				$("<td>").text(data.data[i]['all_like_num']).appendTo(tr);
				$("<td>").text(data.data[i]['weixin_index']).appendTo(tr);
				$("<td>").append(add).appendTo(tr);
				
				tr.appendTo("#ranklist")
			}
		}
	});
}
</script>

